package edu.neusoft.yuejian_09.model;

import java.util.List;

import edu.neusoft.yuejian_09.base.Constant;
import edu.neusoft.yuejian_09.base.RetrofitBaseModel;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.bean.Contest;
import edu.neusoft.yuejian_09.service.ContestService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static edu.neusoft.yuejian_09.base.Constant.BASE_URL;

/**
 * Created by 爽 on 2017/10/9.
 */

public class ContestModel extends RetrofitBaseModel {
    private int flag=1;
    public ContestService contestService;
    public ContestModel(){
        this.contestService=retrofit.create(ContestService.class);
    }


    public void contestlist( final RetrofitListener listener){
        ContestService activityService=retrofit.create(ContestService.class);
        Call call=activityService.getAllContests();
        Callback<List<Contest>> callback=new Callback<List<Contest>>(){
            @Override
            public void onResponse(Call<List<Contest>> call, Response<List<Contest>> response ){
                List<Contest> data=response.body();
                listener.onSuccess(data,flag);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Contest>> call,Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //获取比赛详情
    public void getContestById(int Contest_id, final RetrofitListener listener){
        Call call=contestService.getContestById(Contest_id);
        bindCallback(call,listener, Constant.CONTESTBYID);
    }


    //搜索比赛
    public void getConBySearch(String SearchKey, final RetrofitListener listener){
        ContestService contestService=retrofit.create(ContestService.class);
        Call call=contestService.getContestBySearch(SearchKey);
        Callback<List<Contest>> callback=new Callback<List<Contest>>(){
            @Override
            public void onResponse(Call<List<Contest>> call, Response<List<Contest>> response ){
                List<Contest> data=response.body();
                listener.onSuccess(data,flag);
            }
            @Override
            public  void onFailure(Call<List<Contest>> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }


}
